package com.leyou.trade.web;

import com.leyou.trade.entity.CartItem;
import com.leyou.trade.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cart")
public class CartController {

    @Autowired
    private CartService cartService;


    /**
     * 加入商品到购物车
     *
     * @param cartItem
     * @return
     */
    @PostMapping
    public ResponseEntity<Void> addCart(@RequestBody CartItem cartItem) {

        this.cartService.addCart(cartItem);
        return ResponseEntity.ok().build();
    }

    @GetMapping("/list")
    public ResponseEntity<List<CartItem>> listUserCarts() {

        return ResponseEntity.ok(this.cartService.listUserCarts());
    }
}
